﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Configuration;
using System.Collections.Generic;
using System.Management.Instrumentation;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Manageability;

namespace EntLibContrib.Query.Configuration.Manageability.Parameters
{
	/// <summary>
	/// Represents the configuration information for an instance of
	/// <see cref="EntLibContrib.Query.Configuration.XmlParameterData"/>.
	/// </summary>
	/// <seealso cref="EntLibContrib.Query.Configuration.ParameterData"/>
	/// <seealso cref="NamedConfigurationSetting"/>
	/// <seealso cref="ConfigurationSetting"/>
	[ManagementEntity]
	public partial class XmlParameterSetting : ParameterSetting
	{
		#region Fields
		private string namespaceName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the namespace.
		/// </summary>
		/// <value>The namespace.</value>
		[ManagementConfiguration]
		public string Namespace
		{
			get { return namespaceName; }
			set { namespaceName = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="XmlParameterSetting"/> class.
		/// </summary>
		/// <param name="sourceElement">The source element.</param>
		/// <param name="name">The name.</param>
		/// <param name="namespaceName">The namespace.</param>
		public XmlParameterSetting(XmlParameterData sourceElement, string name, string namespaceName)
			: base(sourceElement, name)
		{
			this.Namespace = namespaceName;
		}
		#endregion

		#region Public Static Methods
		/// <summary>
		/// Returns an enumeration of the published <see cref="XmlParameterSetting"/> instances.
		/// </summary>
		/// <returns>Enumerable list of <see cref="XmlParameterSetting"/> instances</returns>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		[ManagementEnumerator]
		public static IEnumerable<XmlParameterSetting> GetInstances()
		{
			return GetInstances<XmlParameterSetting>();
		}

		/// <summary>
		/// Returns the <see cref="XmlParameterSetting"/> instance corresponding to the provided values for the key properties.
		/// </summary>
		/// <param name="applicationName">Name of the application.</param>
		/// <param name="sectionName">Name of the section.</param>
		/// <param name="name">The command name.</param>
		/// <returns>
		/// The published <see cref="XmlParameterSetting"/> instance specified by the values for the key properties,
		/// or <see langword="null"/> if no such an instance is currently published.
		/// </returns>
		[ManagementBind]
		public static XmlParameterSetting BindInstance(string applicationName,
																									 string sectionName,
																									 string name)
		{
			return BindInstance<XmlParameterSetting>(applicationName, sectionName, name);
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// Saves the changes on the <see cref="XmlParameterSetting"/> to its corresponding configuration object.
		/// </summary>
		/// <param name="sourceElement">The configuration object on which the changes must be saved.</param>
		/// <returns>
		/// 	<see langword="true"/> if changes have been saved, <see langword="false"/> otherwise.
		/// </returns>
		/// <remarks>Must be overridden by subclasses to perform the actual save.</remarks>
		protected override bool SaveChanges(ConfigurationElement sourceElement)
		{
			return XmlParameterDataWmiMapper.SaveChanges(this, sourceElement);
		}
		#endregion
	}
}
